package com.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

import javax.naming.NamingException;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperReport;

import com.dao.BaseDAO;

public class GenerateReport {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private static void generateReport(String path, String sql) throws NamingException, SQLException, JRException {
		BaseDAO dao = new BaseDAO();
		Connection conn = dao.getConnection();
		Statement stmt = (Statement) conn.createStatement();
		ResultSet rs = (ResultSet) stmt.executeQuery(sql);
		JRResultSetDataSource ds = new JRResultSetDataSource(rs);
		JasperReport jasperReport = JasperCompileManager.compileReport(path);
		JasperFillManager.fillReport(jasperReport, new HashMap(),	ds);
	}
	public static void generateEmployeeReport() {
		try {
			generateReport("EmployeeEmptyReport.jrxml", "select * from employees");
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JRException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
